Rules Manager for WPF | ComponentOne
Working With Rules / Understand Range Property
In This Topic
    Understand Range Property
    In This Topic

    The Range property is a collection of RulesEngineRange objects, and each object defines a subset of items, a subset of field or both. This allows the Rules Manager to have control over when and where a rule should be evaluated. 

    The Rule’s Ranges

    Every rule has a scope determined by the Range property. This is a collection of RulesEngineRange which can be defined by a collection of fields and/or a range of items. 

    Range to string conversion

    For xaml and serialization purposes, there is a type-converter from string, with some specific syntax.

    For instance,

    Parse from a String

    The Range property of a rule can be defined using the static method (Parse or TryParse).

    C#
    Copy Code
    rule.Ranges = RulesEngineRangeCollection.Parse(string stringValue)
    // there is also constructor
    rule.Ranges = new RulesEngineRangeCollection(stringValue)
    

    Parse or TryParse methods converts a string representation of a Range into a RulesEngineRangeCollection. The string should follow the syntax rules described above (Example, "3:6:[FirstName];8:12:[LastName]").

    C#
    Copy Code
    // Parse a range string into Ranges collection
    rule.ranges = RulesEngineRangeCollection.Parse("3:6:[FirstName];8:12:[LastName]")
    

    Create a Range Programmatically 

    Build the Range collection manually using code

    C#
    Copy Code
    rule.Ranges = new RulesEngineRangeCollection()
    {
        new RulesEngineRange(fieldName),
        new RulesEngineRange(firstItem, lastItem, fieldName2)
        // ...
    };